package com.hyx.api.service.impl.pc_admin;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hyx.api.domain.CustomerWithdraw;
import com.hyx.api.domain.bo.CustomerWithdrawBo;
import com.hyx.api.domain.vo.CustomerWithdrawVo;
import com.hyx.api.mapper.CustomerWithdrawMapper;
import com.hyx.api.service.pc_admin.ICustomerWithdrawService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 客户提现Service业务层处理
 *
 * @author HK
 * @date 2023-11-06
 */
@RequiredArgsConstructor
@Service
public class CustomerWithdrawServiceImpl implements ICustomerWithdrawService {
    private final CustomerWithdrawMapper customerWithdrawMapper;

    /**
     * 查询客户提现
     *
     * @param id 客户提现主键
     * @return 客户提现
     */
    @Override
    public CustomerWithdrawVo selectCustomerWithdrawById(Long id) {
        //TODO 表以外的字段，写入vo
        return customerWithdrawMapper.selectVoById(id);
    }

    /**
     * 查询客户提现列表
     *
     * @param bo 客户提现
     * @return 客户提现
     */
    @Override
    public List<CustomerWithdrawVo> selectCustomerWithdrawList(CustomerWithdrawBo bo) {
        LambdaQueryWrapper<CustomerWithdraw> lqw = Wrappers.lambdaQuery();
        lqw.eq(ObjectUtils.isNotEmpty(bo.getRecycleOrderId()), CustomerWithdraw::getRecycleOrderId, bo.getRecycleOrderId());
        lqw.eq(ObjectUtils.isNotEmpty(bo.getPhone()), CustomerWithdraw::getPhone, bo.getPhone());
        lqw.eq(ObjectUtils.isNotEmpty(bo.getPrice()), CustomerWithdraw::getPrice, bo.getPrice());
        lqw.eq(ObjectUtils.isNotEmpty(bo.getWithdrawChannel()), CustomerWithdraw::getWithdrawChannel, bo.getWithdrawChannel());
        lqw.eq(ObjectUtils.isNotEmpty(bo.getStatus()), CustomerWithdraw::getStatus, bo.getStatus());
        return customerWithdrawMapper.selectVoList(lqw);
    }

    /**
     * 新增客户提现
     *
     * @param bo 客户提现
     * @return 结果
     */
    @Override
    public int insertCustomerWithdraw(CustomerWithdrawBo bo) {
        CustomerWithdraw customerWithdraw = tranEntityBeforeSave(bo);
        validEntityBeforeSave(customerWithdraw);
        return customerWithdrawMapper.insert(customerWithdraw);
    }

    /**
     * 修改客户提现
     *
     * @param bo 客户提现
     * @return 结果
     */
    @Override
    public int updateCustomerWithdraw(CustomerWithdrawBo bo) {
        CustomerWithdraw customerWithdraw = tranEntityBeforeSave(bo);
        return customerWithdrawMapper.updateById(customerWithdraw);
    }

    /**
     * 批量删除客户提现
     *
     * @param ids 需要删除的客户提现主键
     * @return 结果
     */
    @Override
    public int deleteCustomerWithdrawByIds(Long[] ids) {
        return customerWithdrawMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(CustomerWithdraw entity) {
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 保存前的数据转换
     */
    private CustomerWithdraw tranEntityBeforeSave(CustomerWithdrawBo bo) {
        //TODO 做一些数据转换
        CustomerWithdraw customerWithdraw = new CustomerWithdraw();
        BeanUtils.copyProperties(bo, customerWithdraw);
        return customerWithdraw;
    }
}

